import {
  queryAssetInstitutionList, queryVendor, queryProductType
  , queryAssetNetworkMeshList, queryNetworkInfoList, queryNetInstitutionList, queryOrganization
} from '../api/asset.js'
import {
  querySystemList,
} from '../api/system.js'
import {experType} from '@/api/dict.js'
import * as CommonFn from '../../common'
import {queryExtraTestTargetLinkList} from "../api/extraTestTargetLink";
export function getUnitList(_this,listProp){
  queryAssetInstitutionList({
    pageIndex:1,
    pageSize:2147483646
  }).then(res=>{
    if(res.code===1){
      //data =  _this.$CommonFn.treeChangeToCascaderData(data,'parentOrgId')
      _this[listProp] =  res.data.items;
    }else{
      _this.$Message.error(res.message);
    }
  })
}
export function getVendorList(_this,listProp){
 return queryVendor({pageIndex:1,pageSize:2147483646}).then(res=>{
    if(res.code===1){
      //data =  _this.$CommonFn.treeChangeToCascaderData(data,'parentOrgId')
      _this[listProp] =  res.data.items;
    }else{
      _this.$Message.error(res.message);
    }
  })
}
//queryProductType
export function getProductType(_this,listProp){
   queryProductType({pageIndex:1,pageSize:2147483646}).then(res=>{
    if(res.code===1){
      let data = res.data;
      data =  CommonFn.treeChangeToCascaderData(data,'parentId')
      _this[listProp] =  data;
    }else{
      _this.$Message.error(res.message);
    }
  })
}
export function productPartTypeEscape(type){
  type = Number(type)
  switch(type) {
    case 0: return {
      color: '#2db7f5',
      text: '其他'
    }
    case 1: return {
      color: '#2b85e4',
      text: '应用软件'
    }
    case 2: return {
      color: '#cddc39',
      text: '框架软件'
    }
    case 3: return {
      color: '#8bc34a',
      text: '容器'
    }
    case 4: return {
      color: '#19be6b',
      text: '操作系统'
    }
    case 5: return {
      color: '#c62828',
      text: '设备'
    }
    case 6: return {
      color: '#ed4014',
      text: '固件'
    }
    case 7: return {
      color: '#ff9900',
      text: '文件'
    }
    case 8: return {
      color: '#2db7f5',
      text: '库'
    }
    default: {
      return {
        color: 'default',
        text: '未定义'
      }
    }
  }
}
export function getIndustryList(_this,listProp){
  experType('hwIndustryTypes').then(res=>{
    if(res.code===1){
      _this[listProp] = res.attribute.attribute[0].dictEntryList;
    }else{
      _this.$Message.error(res.message);
    }
  })
}
export function getUnitNatureCodeList(_this,listProp){
  experType('institution_nature').then(res=>{
    if(res.code===1){
      _this[listProp] = res.attribute.attribute[0].dictEntryList;
    }else{
      _this.$Message.error(res.message);
    }
  })
}
export function getAssetServiceType(_this,listProp){
  experType('tests_server_protocol_type').then(res=>{
    if(res.code===1){
      _this[listProp] = res.attribute.attribute[0].dictEntryList;
    }else{
      _this.$Message.error(res.message);
    }
  })
}
export function getNetInfoList(_this,listProp){
  queryNetworkInfoList({pageIndex:1,pageSize:2147483647}).then(res=>{
    if(res.code===1){
      _this[listProp] = res.data.items;
    }else{
      _this.$Message.error(res.message);
    }
  })
}
export function getNetMeshList(_this,listProp,id){
  if(!id){
    _this[listProp] = [];
    return;
  }
  queryAssetNetworkMeshList({netinfoId:id,pageIndex:1,pageSize:2147483647}).then(res=>{
    if(res.code===1){
      _this[listProp] = res.data.items;
    }else{
      _this.$Message.error(res.message)
    }
  })
}
export function getUnitListSystem(_this,listProp){
  queryNetInstitutionList().then(res=>{
    if(res.code===1){
      //data =  _this.$CommonFn.treeChangeToCascaderData(data,'parentOrgId')
      _this[listProp] =  res.data||[];
    }else{
      _this.$Message.error(res.message);
    }
  })
}
export function getSystemList(_this,listProp){
  querySystemList().then(res=>{
    if(res.code===1){
      //data =  _this.$CommonFn.treeChangeToCascaderData(data,'parentOrgId')
      _this[listProp] =  res.data.items||[];
    }else{
      _this.$Message.error(res.message);
    }
  })
}
export function getSystemList1(_this,listProp,id){

  queryExtraTestTargetLinkList({
    extraTestId:id,
    pageIndex:1,
    pageSize:2147483647
  }).then(res=>{
    if(res.code===1){
      //data =  _this.$CommonFn.treeChangeToCascaderData(data,'parentOrgId')
      _this[listProp] =  res.data.items||[];
    }else{
      _this.$Message.error(res.message);
    }
  })
}
export const linkTypeEscape = type => {
  switch (String(type)) {
    case '0': return {
      color: 'orange',
      text: '其他'
    }
    case '1': return {
      color: 'red',
      text: '主题跟踪'
    }
    case '2': return {
      color: 'magenta',
      text: '网站'
    }
    case '3': return {
      color: 'volcano',
      text: '版本控制系统'
    }
    case '4': return {
      color: 'purple',
      text: '警告'
    }
    case '5': return {
      color: 'green',
      text: '物料清单'
    }
    case '6': return {
      color: 'cyan',
      text: '邮件列表'
    }
    case '7': return {
      color: 'blue',
      text: '社会'
    }
    case '8': return {
      color: 'geekblue',
      text: '交谈'
    }
    case '9': return {
      color: 'orange',
      text: '文档'
    }
    case '10': return {
      color: 'red',
      text: '帮助'
    }
    case '11': return {
      color: 'magenta',
      text: '分配'
    }
    case '12': return {
      color: 'volcano',
      text: '许可证'
    }
    case '13': return {
      color: 'purple',
      text: '构建元数据'
    }
    case '14': return {
      color: 'green',
      text: '构建系统'
    }
    case '15': return {
      color: 'cyan',
      text: '发布说明'
    }
    default: {
      return {
        color: 'default',
        text: '未定义'
      }
    }
  }
}
export function getOrgUnitList(_this,listProp){
  return queryOrganization().then(res=>{
    if(res.code===1){
      let data = res.data;
      data =  CommonFn.treeChangeToCascaderData(data,'parentOrgId')
      _this[listProp] =  data;
    }else{
      _this.$Message.error(res.message);
    }
  })
}


